package com.clotingshoppos.modules.product.controller;

import com.clotingshoppos.modules.product.entity.ProductEntity;
import com.clotingshoppos.modules.product.service.ProductService;
import com.clotingshoppos.common.util.RetResponse;
import com.clotingshoppos.common.util.RetResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName: ProductController
 * @Description: 产品Controller
 * @Author: zhandad
 * @Date: 2019-03-16 23:09
 * @Version: v1.0
 */
@Controller
@RequestMapping("/Product")
public class ProductController {
    @Autowired
    ProductService productService;

    @ResponseBody
    @RequestMapping("/list")
    /** 
    * @Description: 返回所有产品列表 
    * @Param: [] 
    * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
    * @Author: zhandad 
    * @Date: 2019/3/21  15:50
    */ 
    public RetResult<List<ProductEntity>> all(){
        List<ProductEntity> ProductList = productService.getProductList();
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findByID")
    /** 
    * @Description: 按照id查找产品 
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductEntity>
    * @Author: zhandad 
    * @Date: 2019/3/21  15:52
    */ 
    public RetResult<ProductEntity> findByID(@RequestBody ProductEntity productEntity){
        ProductEntity product = productService.findById(productEntity);
        return RetResponse.makeOKRsp(product);
        
    }

    @ResponseBody
    @RequestMapping("/findByName")
   /** 
   * @Description: 用产品名查找的接口 
   * @Param: [productEntity] 
   * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
   * @Author: zhandad 
   * @Date: 2019/3/24  21:37
   */ 
    public RetResult<List<ProductEntity>> findByName(@RequestBody ProductEntity productEntity){
        List<ProductEntity> ProductList =  productService.findByName(productEntity.getName());
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findByType")
    /** 
    * @Description: 用type查找一类产品的接口 
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
    * @Author: zhandad 
    * @Date: 2019/3/24  21:37
    */ 
    public RetResult<List<ProductEntity>> findByType(@RequestBody ProductEntity productEntity){
        List<ProductEntity> ProductList =  productService.findByType(productEntity.getType());
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findBySex")
   /** 
   * @Description: 用适用性别查找一类产品的接口 
   * @Param: [productEntity] 
   * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
   * @Author: zhandad 
   * @Date: 2019/3/24  21:38
   */ 
    public RetResult<List<ProductEntity>> findBySex(@RequestBody ProductEntity productEntity){
        List<ProductEntity> ProductList =  productService.findBySex(productEntity.getSex());
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findByNameAndSize")
    /** 
    * @Description: 按照产品名与适用性别查找一类产品的接口 
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
    * @Author: zhandad 
    * @Date: 2019/3/24  21:38
    */ 
    public RetResult<List<ProductEntity>> findByNameAndSize(@RequestBody ProductEntity productEntity){
        List<ProductEntity> ProductList =  productService.findByNameAndSize(productEntity.getName(),productEntity.getSize());
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findByNameAndColor")
    /** 
    * @Description: 按照产品名与颜色查找一类产品的接口
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductEntity>>
    * @Author: zhandad 
    * @Date: 2019/3/25  9:40
    */ 
    public RetResult<List<ProductEntity>> findByNameAndColor(@RequestBody ProductEntity productEntity){
        List<ProductEntity> ProductList = productService.findByNameAndColor(productEntity.getName(), productEntity.getColor());
        return RetResponse.makeOKRsp(ProductList);
    }

    @ResponseBody
    @RequestMapping("/findByNameAndSizeAndColor")
    /** 
    * @Description: 按照产品名与尺码与颜色查找一类产品的接口
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductEntity>
    * @Author: zhandad 
    * @Date: 2019/3/24  21:33
    */ 
    public RetResult<ProductEntity> findByNameAndSizeAndColor(@RequestBody ProductEntity productEntity){
        ProductEntity product =  productService.findByNameAndSizeAndColor(productEntity.getName(), productEntity.getSize(), productEntity.getColor());
        return RetResponse.makeOKRsp(product);
    }

    @ResponseBody
    @RequestMapping("/updateProduct")
    /** 
    * @Description: 更新某一产品信息的接口 
    * @Param: [productEntity] 
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductEntity>
    * @Author: zhandad 
    * @Date: 2019/3/24  21:33
    */ 
    public RetResult<ProductEntity> updateProduct(@RequestBody ProductEntity productEntity){
        ProductEntity product = (ProductEntity) productService.update(productEntity);
        return RetResponse.makeOKRsp(product);
    }

    @ResponseBody
    @RequestMapping("/addProduct")
    /**
    * @Description: 增加产品的接口
    * @Param: [productEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:34
    */
    public RetResult<ProductEntity> addProduct(@RequestBody ProductEntity productEntity){
        ProductEntity product = (ProductEntity) productService.add(productEntity);
        return RetResponse.makeOKRsp(product);
    }

    @ResponseBody
    @RequestMapping("/deletProduct")
    /**
    * @Description: 删除某一产品的接口
    * @Param: [productEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:35
    */
    public RetResult<ProductEntity> deletProduct(@RequestBody ProductEntity productEntity){
        ProductEntity product = (ProductEntity) productService.delete(productEntity);
        return RetResponse.makeOKRsp(product);
    }

}
